package com.sxz.sbs.module.sale.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.sale.mode.ImgBackBean;
import com.sxz.sbs.module.sale.view.EditPhotoView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;


/**
 * 编辑图片P
 */

public class EditPhotoPresenter extends RxPresenter<EditPhotoView>{
    /**
     * 编辑图片 删除图片
     * @param map
     */
    public void deletePhoto (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().deleteStallPhoto(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onDeletePhotoSuccess();
                    }
                })
        );
    }
    /**
     * 上传图片
     */
    public void uploadPhoto (int stallId,List<MultipartBody.Part> file) {
        addSubscribe(App.getInstance().getApi().saveStallPhoto(stallId,file)
                .compose(RxUtil.<List<ImgBackBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<ImgBackBean>>(mView){
                    @Override
                    public void onNext(List<ImgBackBean> data) {
                        mView.onUploadPhotoSuccess(data);
                    }
                })
        );
    }
  /*  *//**
     * 测试
     *//*
    public void test (int type, List<MultipartBody.Part> file) {
        addSubscribe(App.getInstance().getApi().testUpload(type,file)
                .compose(RxUtil.<ImgBackBean>handleResult())
                .subscribeWith(new RxSubscriber<ImgBackBean>(mView){
                    @Override
                    public void onNext(ImgBackBean data) {
                       // mView.onUploadPhotoSuccess(data);
                    }
                })
        );
    }*/
}
